<template>
    <div class="box">
        <h3>点击了{{$store.state.time}} 次,当前次数为{{sum}}</h3>
        <button @click="addition">+</button>
        <button @click="subtraction">-</button>
        <button @click="evenAdd">偶数加法</button>
        <button @click="asyncAdd">异步加法</button>
    </div>
</template>

<script>
    import { mapState,mapGetters,mapActions } from 'vuex';
    export default {
        name: "App",
        computed:{
            //mapState()返回值: { time(){return this.$store.state['time']}}
            ...mapState(['time']),
            ...mapGetters(['sum']) // { sum(){return this.$store.getters['time']}}
            // sum(){
            //     return this.$store.getters.sum;
            // }
            // time(){
            //     return this.$store.state.time;
            // }
        },
        methods:{
            ...mapActions(['addition','subtraction','evenAdd','asyncAdd'])
            // addition(){
            //     //通知vuex去增加
            //     this.$store.dispatch('addition');
            // },
            // subtraction(){
            //     this.$store.dispatch('subtraction');
            // },
            // evenAdd(){
            //     this.$store.dispatch('evenAdd');
            // },
            // asyncAdd(){
            //     this.$store.dispatch('asyncAdd');
            // }
        }
    }
</script>

<style scoped>
    .box{
        margin-left: 30px;
    }
</style>